﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using LDSP.BRL;

namespace LDSP.Util
{
    public class CodificationExport : CodificationExportBase<Catalog, Codification>
    {
        protected override void InitialRows(DataTable dt, IList<Codification> codifications)
        {
            foreach (Codification cod in codifications)
            {
                dt.Rows.Add(cod.Category.Name,
                            cod.Name,
                            cod.Organization,
                            cod.ReferenceNumber,
                            cod.ReleaseDT,
                            cod.ImplementDT,
                            cod.Summary,
                            cod.KeyItems,
                            !string.IsNullOrEmpty(cod.InvalidDescription) ? cod.InvalidDescription : GenerateInvalidList(cod)
                            );
            }
        }

        protected override void InitialColumns(DataTable dt)
        {
            dt.Columns.Add("Category");
            dt.Columns.Add("Title");
            dt.Columns.Add("Agency");
            dt.Columns.Add("OrderNumber");
            dt.Columns.Add("IssueDate");
            dt.Columns.Add("EffectiveDate");
            dt.Columns.Add("Summary");
            dt.Columns.Add("KeyPoints");
            dt.Columns.Add("Invalidate");
        }

        protected override IList<Catalog> GetAllCatalogs()
        {
            return new Catalog().GetAllCatalogs();
        }

        protected override void GenerateList(IDictionary<string, DataTable> dataTables, Catalog cata)
        {
            IList<Codification> codifications = new Codification().GetListByCatalogID(cata.ID);

            string name = GetFullName(cata);

            dataTables.Add(name, ConstructDT(codifications));
        }
    }
}